#include <iostream>
#include "test.h"

using namespace std;

//product base class
class uProduct {
public:
    uProduct(void)
    {
        cout << "uProduct constructor" << endl;
    }
    virtual ~uProduct() {cout << "uProduct delete" << endl; }

    virtual void show(void) = 0;
};

class uProduct_A : public uProduct {
public:
    uProduct_A(void):uProduct() {};
    virtual ~uProduct_A() {};

    virtual void show(void)
    {
        cout << "uProduct_A show!" << endl;
    }
};

class uProduct_B : public uProduct {
public:
    uProduct_B(void):uProduct() {};
    virtual ~uProduct_B() {};

    virtual void show(void)
    {
        cout << "uProduct_B show!" << endl;
    }
};

//factory base class
class uFactory {
public:
    uFactory(void)
    {
        cout << "uFactory constructor" << endl;
    }
    virtual ~uFactory() { cout << "uFactory delete" << endl; }

    virtual uProduct* creat(void) = 0;
};

class uFactory_A : public uFactory {
public:
    uFactory_A(void):uFactory() {};
    virtual ~uFactory_A() {};

    virtual uProduct* creat(void)
    {
        cout << "uFactory_A creat" << endl;
        return new uProduct_A();
    }
};

class uFactory_B : public uFactory {
public:
    uFactory_B(void):uFactory() {};
    virtual ~uFactory_B() {};

    virtual uProduct* creat(void)
    {
        cout << "uFactory_B show" << endl;

        return new uProduct_B();
    }
};
#ifdef _WIN32
#include "win_ulock.h"
win_ulock_base mc;
#endif
void factory_test(void)
{
    uFactory *pF;
    uProduct *pP;
#ifdef _WIN32
    win_ulock c(&mc);
#endif
    pF = new uFactory_A();

    pP = pF->creat();

    pP->show();

    delete pF;
    delete pP;

    pF = new uFactory_B();

    pP = pF->creat();

    pP->show();

    delete pF;
    delete pP;
}
